package gui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.Vector;

import javax.swing.JPanel;

import diagramobjects.DiagramObjects;
import diagramobjects.SelectionRect;

import program.PaintObjects;


public class DrawingPanel extends JPanel {
	

	private PaintObjects PaintObjs;
	private DiagramObjects GeomObjs;
	private SelectionRect SRect;
	private Vector<Integer> IfSelected;
	
	
	
	//PanelLineTool = new LineTool(GeomObjs);
	//DatabaseConnection DBCon = new DatabaseConnection();
		
	/**
	 * tworzy ArrayList obiektw na panelu 
	 */
	public DrawingPanel() 
	{
		super();
		
		PaintObjs = new PaintObjects();
		GeomObjs = new DiagramObjects();
		IfSelected = new Vector<Integer>();
		SRect = new SelectionRect();
		//DatabaseConnection.InitializeDatabaseConnection();
		
	}
	
	public Vector<Integer> getSelected()
	{
		return IfSelected;
	}
	
	public void addSelected()
	{
		IfSelected.add(0);
	}
	
	public void changeSelection(Integer i)
	{
		if (IfSelected.get(i) == 1)
			IfSelected.set(i, 0);
		else
			IfSelected.set(i,1);
		repaint();
		
	}
	
	public void addSelection(Integer i)
	{
			IfSelected.set(i,1);
	}
	
	public void removeSelection(Integer i)
	{
			IfSelected.set(i,0);
	}
	
	public void CleanAllSelections()
	{
		for (int i = 0 ; i < IfSelected.size(); ++i)
		{
			IfSelected.set(i,0);
		}
	}
	
	public Integer getIfElementSelected(Integer i)
	{
		return IfSelected.get(i);
	}
	
	public DiagramObjects GetGeometricObjects()
	{
		return GeomObjs;
	}
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		
	// real drawing
		for (int i = 0; i < GeomObjs.GetSize(); ++i) 
		{
			GeomObjs.GetGeometricbjectFromPanel(i).Draw(g, PaintObjs);
			if (IfSelected.get(i) == 1)
				GeomObjs.GetGeometricbjectFromPanel(i).DrawSelection(g, PaintObjs);
			
			SRect.Draw(g, PaintObjs);
			//PaintObjs.DrawGrid(g, 20);
		}
		

		
	
	//}-=-_-=-{ real drawing
	}
	
	public void SetSelectionRect(Integer x, Integer y, Integer w, Integer h)
	{
		SRect.SetSelection(x, y, w, h);
	}
	
	public void ResetSelectionRect()
	{
		SRect.Reset();
	}
	
	
	
}
